﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SZSLSystem.Common;

namespace SZSLSystem.Web.Admin.Authority
{
    public partial class Edit : SZSLSystem.Web.UI.ManagePage
    {
        /// <summary>
        /// 页面初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                JscriptMsg(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                return;
            }
            if (!Page.IsPostBack)
            {
                ShowInfo(Guid.Parse(Request.QueryString["ID"]));
            }
        }

       /// <summary>
        /// 赋值操作
       /// </summary>
       /// <param name="ID">物流编号</param>
        private void ShowInfo(Guid ID)
        {
            //
            //权限
            //
            SZSLSystem.BLL.Authority bll = new SZSLSystem.BLL.Authority();
            SZSLSystem.Model.Authority model = bll.GetModel(ID);

            this.txtName.Text = model.AuthorityName;
            this.txtAbbreviation.Text = model.Abbreviation;
            if (model.ParentID.ToString().ToUpper() == AuthorityID)
            {
                this.lblParent.Text = "系统权限";
            }
            else
            {
                this.lblParent.Text = new SZSLSystem.BLL.Authority().GetModel(model.ParentID.Value).AuthorityName;
            }
            this.rblLabel.SelectedValue = model.Label.ToString();
            this.txtDescription.Text = model.Description;
            this.rblIsLock.SelectedValue = model.Status.ToString();
            this.txtSort.Text = model.Sort.ToString();
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                //
                //权限
                //
                SZSLSystem.BLL.Authority bll = new SZSLSystem.BLL.Authority();
                SZSLSystem.Model.Authority model = bll.GetModel(Guid.Parse(Request.QueryString["ID"]));
                model.AuthorityName = this.txtName.Text.Trim();
                model.Abbreviation = this.txtAbbreviation.Text.Trim();
                model.Description = this.txtDescription.Text.Trim();
                model.Label = int.Parse(this.rblLabel.SelectedValue);
                model.Status = int.Parse(this.rblIsLock.SelectedValue);
                model.Sort = int.Parse(this.txtSort.Text.Trim());
                bll.Update(model);
                //
                //保存日志
                //
                SaveLogs("修改操作权限成功！", 0);

                JscriptPrint("修改操作权限成功啦！", "List.aspx", "Success");
            }
            catch (Exception err)
            {
                //
                //异常日志写入
                //
                SaveLogs(err.ToString(), 1);

                JscriptMsg(350, 230, "错误提示", "<b>出现错误了！</b>修改操作权限失败啦！", "", "Error");
            }
        }
    }
}
